<template>
    <div class="material-container" v-loading="loading" :class="{ 'is-mobile': $isMobile }">
        <div v-for="item in datas" :key="item.id" class="material-item" v-if="item.materials && item.materials.length">

            <div class="item-header">
                <div class="item-title">{{ item.title }}</div>

            </div>

            <div class="item-infos">
                <div class="item-detail" v-for="(material, index) in item.materials" :key="index">
                    <div class="title">{{ material.title }}</div>
                    <div class="download" @click="handleDownload(material)">下载</div>
                </div>
            </div>


        </div>

    </div>
</template>

<script>
export default {
    name: "materialList",
    data() {
        return {
            loading: false,
            datas: [

            ]
        }
    },
    mounted() {
        this.getData();
    },
    methods: {

        async getData() {
            const loading = this.$loading();
            const { data } = await this.$fetch.get(`/api/topic/materialList`);
            this.datas = data
            loading.close()

        },

        handleDownload(material) {
            this.$download(material.link)
        },

        hanndleMore(item) {
            this.$router.push({
                path: "/topic/teacher",
                query: {
                    topicId: item.topicId
                }
            })
        }

    }
}
</script>

<style lang="less" scoped>
.material-container {
    padding-left: 60px;
    width: 100%;
    box-sizing: border-box;
    padding-bottom: 25px;
    height: 100%;


    .material-item {
        margin-top: 25px;
        display: flex;
        flex-direction: column;
        font-size: 16px;

        .item-header {
            display: flex;
            justify-content: space-between;
            align-items: center;

            .item-title {
                height: 34px;
                min-width: 166px;
                max-width: max-content;
                background: url(~@/assets/topic-title-bg.png) center center no-repeat;
                background-size: cover;
                font-family: PingFangSC, PingFang SC;
                font-weight: 600;
                font-size: 16px;
                text-indent: 14px;
                color: #FFFFFF;
                line-height: 34px;
                text-align: left;
                font-style: normal;
                cursor: default;
            }

            .more {
                font-family: PingFangSC, PingFang SC;
                font-weight: 400;
                font-size: 14px;
                color: #3560AB;
                text-align: right;
                font-style: normal;
                margin-right: 30px;
                cursor: pointer;

            }
        }



        .item-infos {
            display: flex;
            flex-direction: column;
            flex-wrap: wrap;
            width: 100%;
            margin-top: 16px;

            .item-detail {
                display: flex;
                align-items: center;
                width: 100%;
                height: 40px;
                justify-content: space-between;
                align-items: center;
                border-bottom: 1px solid #efefef;

                .title {
                    font-family: PingFangSC, PingFang SC;
                    font-weight: 400;
                    font-size: 14px;
                    color: #333333;
                    text-align: left;
                    font-style: normal;
                    flex: 1;
                    overflow: hidden;
                    white-space: nowrap;
                    text-overflow: ellipsis;
                }

                .download {
                    font-family: PingFangSC, PingFang SC;
                    font-weight: 400;
                    font-size: 14px;
                    color: #3560AB;
                    text-align: right;
                    font-style: normal;
                    margin-right: 30px;
                    cursor: pointer;

                    &:hover {
                        text-decoration: underline;
                    }
                }
            }
        }


    }


}

.material-container.is-mobile {
    padding-left: 10px;

    .material-item {
        margin-top: 10px;
    }
}
</style>